package stack;

import linkedlist.LinkedList;

/**
 * 链表栈
 *
 * @author: yxyi
 * @mail: yxyi@iflytek.com
 * @date: 2019-01-06
 */
public class LinkedListStack<E> implements Stack<E> {

    // 需要不断new创建Node节点，数组栈需要拷贝数据
    private LinkedList<E> list;

    public LinkedListStack() {
        list = new LinkedList<>();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }
}
